package com.gonsin.gview.logic.validate.formItem;

import com.gonsin.gview.logic.exceptions.BaseGViewException;
import com.gonsin.gview.logic.validate.IModelValidate;
import com.gonsin.gview.logic.validate.ValidateContext;
import com.gonsin.gview.logic.validate.data.ListDataValidate;
import com.gonsin.gview.model.form.GSelectorModel;
import org.apache.commons.lang3.StringUtils;

public class SelectorValidate implements IModelValidate<GSelectorModel> {
    @Override
    public void validate(ValidateContext context, GSelectorModel board) {
        ListDataValidate listDataValidate = new ListDataValidate();
        if(board.getListData() == null){
            throw new BaseGViewException("【%s】中的@GSelector 没有设置" +
                    "listData");
        }
        listDataValidate.validate(context, board.getListData());

        // 校验showIf的语法

        // 校验onChangeAction
        if(StringUtils.isNotEmpty(board.getButtonId())){
            if(null == context.getActionService().findActionById(board.getButtonId())){
                throw new BaseGViewException("【%s】中的@GSelector onChangeAction 找不到对应的action");
            }
        }
    }
}
